//
//  Model.swift
//  颖姐姐
//
//  Created by wu on 2017/6/22.
//  Copyright © 2017年 wu. All rights reserved.
//

import Foundation
import YYModel


class picModel:NSObject{
    var key:String?
    
    init(dic:[String:AnyObject]) {
        super.init()
        yy_modelSet(with: dic)
    }
    override var description: String{
        return yy_modelDescription()
    }
}

class Model:NSObject {
    
    
    var pics = [picModel]()

    var content:String?
    var distance:String?
    var id = 0

    var price:String?
    var range:String?
    var user_idn = 0
    var create_time:String?
    var user:User?
    
    var height:CGFloat = 0
    var pHeight:CGFloat = 0

    init(dic:[String:AnyObject]) {
        super.init()
        yy_modelSet(with: dic)
        
        guard let imgs = dic["images"] as? [[String:AnyObject]] else {
            updateHeight(picCount: 0)
            return
        }
        
        for dic  in imgs {
            pics.append(picModel(dic: dic))
        }
        updateHeight(picCount: imgs.count)
    }
    
    fileprivate func updateHeight(picCount:Int){
        
        height = 50 + 44 + 30
        let margin:CGFloat = 15
        
        let size = CGSize(width:UIScreen.main.bounds.width - margin * 2, height:CGFloat(MAXFLOAT))
//        let text = self as NSString
        if let text = content {
            
            height  += text.boundingRect(with: size, options:.usesLineFragmentOrigin, attributes: [NSFontAttributeName : UIFont.systemFont(ofSize: 13)], context:nil).height
        }
        
        let pMargin:CGFloat = 5
        let w = (UIScreen.main.bounds.width - 30 - pMargin * 2) / 3 + pMargin
        
        pHeight = CGFloat((picCount + 2) / 3) * w - pMargin
        height += pHeight
    }
    
    
    override var description: String{
        
        return yy_modelDescription()
    }
}

class User: NSObject {
    var company_name:String?
    var id = 0
    var nickname:String?
//    "city" : 0,
    var profile:String?
    var head_pic:String?
}
